Erlang was originally developed by Ericsson for use in telecom switching devices. Recently SMP/multi-core support has been added. Erlang has lightweight processes and distributed message-based inter-process communication patterned after Hoare's CSP. Processes are created using the spawn() command, and messages are sent with the ! command and received with receive(). Unlike CSP and Concurrent ML, Erlang's messages are asynchronous. With this difference John Reppy considers Erlang to be an Actor language (Concurrent Programming in ML, p. 37). Concurrent Haskell also uses asynchronous messages.
My Erlang source code is here.
| language | cities | iterations (ants) | cores | time (secs) | speedup |
|---|---|---|---|---|---|
| Erlang | 200 | 100 | 1 | 67.8 | |
| Erlang | 200 | 100 | 2 | 35.6 | 1.90 |
| GHC Haskell | 200 | 100 | 1 | 10.2 | |
| GHC Haskell | 200 | 100 | 2 | 6.9 | 1.48 |
| MLton Standard ML | 200 | 100 | 1 | 0.52 | |
| Alice Standard ML | 200 | 100 | 1 | 38.2 |
All tests were performed on AMD Athlon A64x2 (dual core) 4400 CPU (2.2 GHz), 2048Meg memory, Debian Linux 2.6.15-1-k7-smp, Erlang 5.5/OTP R11B, GHC 6.5.20060620 (compile: -threaded -O; runtime: +RTS -K500m -H1000m -N2), MLton 20060213-1. Alice-1.2-1 was tested on the same hardware booted with Windows XP Pro SP2, as the Debian Linux package requires an older version of libgmp3 (Multiprecision arithmetic library) which conflicts with MLton and probably GHC.
Erlang is much slower than the others. Erlang is a bytecode interpreted virtual machine while the others (except 2nd-slowest Alice) are native code compilers. Like Haskell, Erlang has immutable (single assignment) variables which force lots of copying. Unlike Standard ML and Haskell, no array type is provided so I had to inefficiently implement them using dictionaries. In Erlang each process (thread) does have a separate heap, so there is little interference between processes due to garbage collection. Near perfect speedup is achieved.
Here are some language comparisons:
| language | language type | typing | evaluation | single assign- ment | SMP / Multi- Core | distrib- uted | native compiled | messaging |
|---|---|---|---|---|---|---|---|---|
| Alice Standard ML | functional | static with type inference | strict plus lazy futures | - | - | Yes | - | RPC |
| MLton Standard ML | functional | static with type inference | strict | - | - | - | Yes | sync |
| GHC Haskell | functional | static with type inference | lazy | Yes | Yes | (GpH with PVM) | Yes | async |
| Erlang | functional | dynamic | strict | Yes | Yes | Yes | - | async |